import { getSkipStyle } from "../api/theme";
const formatTime = (date) => {
  const year = date.getFullYear();
  const month = date.getMonth() + 1;
  const day = date.getDate();
  const hour = date.getHours();
  const minute = date.getMinutes();
  const second = date.getSeconds();

  return (
    [year, month, day].map(formatNumber).join("/") +
    " " +
    [hour, minute, second].map(formatNumber).join(":")
  );
};

const formatNumber = (n) => {
  n = n.toString();
  return n[1] ? n : "0" + n;
};

const getSkipStyleAct = (extId) => {
  console.log("调用extId: ", extId);
  let obj = {
    actId: extId,
  };
  getSkipStyle(obj)
    .then((res) => {
      console.log("res---主题---APP.js: ", res);
      if (res.success) {
        return res.data;
        //给styleInfo赋值
        // that.globalData.theme = res.data;
        // setTimeout(() => {
        //   wx.switchTab({
        //     url: "/pages/home/home",
        //   });
        // }, 50);
      }
    })
    .catch((err) => { });
};

/*获取当前页url*/
const getCurrentPageUrl = () => {
  let pages = getCurrentPages()    //获取加载的页面
  let currentPage = pages[pages.length - 1]    //获取当前页面的对象
  let url = currentPage.route    //当前页面url
  return url
}
/*获取当前页参数*/
const getCurrentPageParam = () => {
  let pages = getCurrentPages()    //获取加载的页面
  let currentPage = pages[pages.length - 1]    //获取当前页面的对象
  let options = currentPage.options    //如果要获取url中所带的参数可以查看options
  return options
}

module.exports = {
  formatTime: formatTime,
  getSkipStyleAct: getSkipStyleAct,
  getCurrentPageUrl,
  getCurrentPageParam
};
